﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using RapidSalesAdminPortalAPI.DataAccess;
using RapidSalesAdminPortalAPI.Models;
using WebAPI.Common.Attributes;
using WebAPI.Common;
using WebAPI.Controllers;
using WebAPI.Models;

namespace RapidSalesAdminPortalAPI.Controllers
{
    [Authorize]
    [Route("api/[controller]")]
    [ApiController]
    /// <summary>
    /// 订单支付接口
    /// </summary>
    public class OrderPayController : ParentController
    {
        private readonly RS_AdmPortalContext _db;
        private readonly ILogUtility _logUtility;
        private readonly ILogger _logger;
        private readonly IDataProtectorUtility _dataProtectorUntility;

        public OrderPayController(RS_AdmPortalContext db
            , IConfiguration configuration, ILogUtility logUtility, ILogger<OrderPayController> logger, IDataProtectorUtility dataProtectorUntility)
        {
            _db = db;
            _logUtility = logUtility; // sample code for DI of common utility class
            _logger = logger;
            _dataProtectorUntility = dataProtectorUntility;
        }

        [Log("OrderPay", "Pay", description: "OrderPay/Pay", LogType: Enums.LogType.AdministratorAccountLog)]
        [HttpPut("Pay")]
        public async Task<ActionResult<ResultMsg>> Pay([FromBody] PayRequest request)
        {
            var resultMsg = new ResultMsg();
            try
            {
                return resultMsg.SetResultMsg(
                  (int)ResultCode.Success,
                  HelperUtility.GetDescription(ResultCode.Success),
                  null);
            }
            catch (Exception ex)
            {
                _logger.LogError("FrIpProduct/UpdateFrIpProduct Error:" + ex.Message);
                return resultMsg.SetResultMsg(
                 (int)ResultCode.ErrorOnRequestUnMarshalling,
                 HelperUtility.GetDescription(ResultCode.UserNotFound),
                 null);
            }
        }
    }
}
